<?php
/***************************************************************************
 *   copyright : (C) 2009 Udrea Cristian
 *   site : http://code.google.com/p/testauction-php
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as 
 *   published by the Free Software Foundation; either version 2 of the
 *   License, or (at your option) any later version. Although none of the
 *   code may be sold. If you have been sold this script, get a refund.
 ***************************************************************************/
include(APP_ROOT.'include/classes/constants.php');
include('../library/functions.php');
#=======CONSTANTS=======
$ROWSPERPAGE = 10;
#=======================

//$sql = "SELECT product_name, description, pict1_url FROM ".TBL_PRODUCTS." WHERE product_id BETWEEN ? AND ?";
$sql = "SELECT product_id, product_name, description, pict1_url FROM ".TBL_PRODUCTS;
$result = execute_query($sql);//, array($startindex, $endindex));
$pagingLink = getPagingLink($sql, $ROWSPERPAGE);
?>
<p>&nbsp;</p>
 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
   <tr align="center" class="listTableHeader">
	 <td colspan="7" class="text"><form name="form" action="index.php" method="get">
	   <br />
	   Numele produsului&nbsp;
	   <input type="hidden" name="view" id="view" value="search"/>
       <input type="text" class="box" name="q" id="q" />
	   <input type="submit" class="box" name="submit" id="submit" value="Cauta" />
	 </form></td>
   </tr>
   <tr align="center" class="listTableHeader">
     <td>Nume Produs</td>
     <td>Descriere</td>
     <td width="75">Foto</td>
     <td>Modifica</td>
     <td>Sterge</td>
   </tr>
<?php
if(count($result) > 0) {
	for($i = 0; $i < count($result); $i++) {
		if ($i%2) {
			$class = 'row1';
		} else {
			$class = 'row2';
		}
?>
		<tr class="<?php echo $class; ?>"> 
		   <td><a href="index.php?view=detail&productId=<?php echo $result[$i]['product_id']; ?>"><?php echo $result[$i]['product_name']; ?></a></td>
		   <td align="center"><?php echo substr($result[$i]['description'], 0, 15); ?></a></td>
		   <td width="75" align="center"><img src="../../produse/thumb_<?php echo $result[$i]['pict1_url']; ?>"/></td>
		   <td align="center">
			<a href="javascript:modifyProduct(<?php echo $result[$i]['product_id']; ?>);"><img style="border: 0;" src="../include/edit.png"/>
		   </a></td>
		   <td align="center">
			<a href="javascript:deleteProduct(<?php echo $result[$i]['product_id']; ?>);"><img style="border: 0;" src="../include/delete.png"/>
		   </a></td>
		   <td align="center">
			<a href="javascript:auctionWithProduct(<?php echo $result[$i]['product_id']; ?>);"><img style="border: 0;" src="../include/auction.png"/>
		   </a></td>
		</tr>
<?php
	}
?>
  <tr><td colspan="7" align="center"><?php echo $pagingLink; ?></td></tr>
<?php 
}
else {
?>
  <tr><td colspan="7" align="center">Nu au fost adaugate produse</td></tr>
<?php
}
?>
  <tr><td colspan="7">&nbsp;</td></tr>
  <tr><td colspan="7" align="right"><input type="button" value="Add Product" class="box" onClick="addProduct()"></td></tr>
 </table>
 <p>&nbsp;</p>
